<template>
  <div class="workbench-container">
    <h2>维修工作台</h2>
    <!-- 待处理工单 -->
    <el-card class="workbench-card">
      <template #header>
        <div class="card-header">
          <span>待处理工单</span>
        </div>
      </template>
      <el-table :data="pendingOrders" style="width: 100%">
        <el-table-column prop="id" label="工单号" width="120" />
        <el-table-column prop="deviceName" label="设备名称" width="180" />
        <el-table-column prop="problem" label="故障描述" />
        <el-table-column prop="submitTime" label="提交时间" width="180" />
        <el-table-column prop="status" label="状态" width="120">
          <template #default="{ row }">
            <el-tag :type="row.status === '待处理' ? 'warning' : 'success'">{{ row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button type="primary" size="small" @click="handleProcess(row)">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 处理工单对话框 -->
    <el-dialog v-model="dialogVisible" title="处理工单" width="50%">
      <el-form :model="processForm" label-width="100px">
        <el-form-item label="维修结果">
          <el-input v-model="processForm.result" type="textarea" rows="3" placeholder="请输入维修结果" />
        </el-form-item>
        <el-form-item label="处理状态">
          <el-select v-model="processForm.status" style="width: 100%">
            <el-option label="已修复" value="fixed" />
            <el-option label="需要更换零件" value="parts_needed" />
            <el-option label="无法修复" value="cannot_fix" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitProcess">确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

// 模拟数据
const pendingOrders = ref([
  {
    id: 'RO001',
    deviceName: '超声波清洗机',
    problem: '无法启动',
    submitTime: '2024-01-20 10:30:00',
    status: '待处理'
  },
  {
    id: 'RO002',
    deviceName: 'X光机',
    problem: '显示屏故障',
    submitTime: '2024-01-20 11:15:00',
    status: '待处理'
  }
])

const dialogVisible = ref(false)
const currentOrder = ref(null)
const processForm = reactive({
  result: '',
  status: ''
})

const handleProcess = (row) => {
  currentOrder.value = row
  dialogVisible.value = true
}

const submitProcess = () => {
  // TODO: 实现工单处理逻辑
  ElMessage.success('工单处理成功')
  dialogVisible.value = false
}
</script>

<style scoped>
.workbench-container {
  padding: 20px;
}

.workbench-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>